/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package onlinebuy;

/**
 *
 * @author Yang Wu
 */

import javax.swing.JFrame;
import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.JButton;
import java.sql.*;
import javax.swing.JOptionPane;
public class MyShop {

private JFrame f1;
private JButton b1,b2,b3,b4,b5,b6;
 
 
 String p=new String();
public  MyShop() throws Exception{
    f1=new JFrame("Online Shop");
    f1.setLayout(new GridLayout(2,3));
    b1=new JButton("Iterm1");
    b2=new JButton("Iterm2");
    b3=new JButton("Iterm3");
    b4=new JButton("Iterm4");
    b5=new JButton("Iterm5");
    b6=new JButton("Iterm6");
    f1.add(b1);f1.add(b2);f1.add(b3);
    f1.add(b4);f1.add(b5);f1.add(b6);

   thehandler handler=new thehandler();

   b1.addActionListener(handler);
   b2.addActionListener(handler);
   b3.addActionListener(handler);
   b4.addActionListener(handler);
   b5.addActionListener(handler);
   b6.addActionListener(handler);

    f1.setSize(800,600);
    f1.setVisible(true);
}

    

    private class thehandler implements ActionListener{

        
       
        public void actionPerformed(ActionEvent event) {
            
            
            

            if(event.getSource()==b1){
            new Order();
             try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection cn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/onlineshop","root","121121");
            Statement s = cn.createStatement();
            int r = s.executeUpdate("UPDATE `onlineshop`.`iterms` SET `quantity`= `quantity`-1 WHERE `iterm_id`='1'");
            

            }

            catch (Exception ex) {
            System.err.println("ERROR: " + ex);
        }


            
                }
            if(event.getSource()==b2){
                
            new Order();
             try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection cn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/onlineshop","root","121121");
            Statement s = cn.createStatement();
            int r = s.executeUpdate("UPDATE `onlineshop`.`iterms` SET `quantity`= `quantity`-1 WHERE `iterm_id`='2'");


            }

            catch (Exception ex) {
            System.err.println("ERROR: " + ex);
        }
            }
            if(event.getSource()==b3){
                new Order();
              try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection cn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/onlineshop","root","121121");
            Statement s = cn.createStatement();
            int r = s.executeUpdate("UPDATE `onlineshop`.`iterms` SET `quantity`= `quantity`-1 WHERE `iterm_id`='3'");


            }

            catch (Exception ex) {
            System.err.println("ERROR: " + ex);
        }
            }
            if(event.getSource()==b4){
                 new Order();
              try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection cn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/onlineshop","root","121121");
            Statement s = cn.createStatement();
            int r = s.executeUpdate("UPDATE `onlineshop`.`iterms` SET `quantity`= `quantity`-1 WHERE `iterm_id`='4'");


            }

            catch (Exception ex) {
            System.err.println("ERROR: " + ex);
        }
            }
            if(event.getSource()==b5){
                  new Order();
             try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection cn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/onlineshop","root","121121");
            Statement s = cn.createStatement();
            int r = s.executeUpdate("UPDATE `onlineshop`.`iterms` SET `quantity`= `quantity`-1 WHERE `iterm_id`='5'");


            }

            catch (Exception ex) {
            System.err.println("ERROR: " + ex);
        }
            }
            if(event.getSource()==b6){
                new Order();
              try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection cn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/onlineshop","root","121121");
            Statement s = cn.createStatement();
            int r = s.executeUpdate("UPDATE `onlineshop`.`iterms` SET `quantity`= `quantity`-1 WHERE `iterm_id`='6'");


            }

            catch (Exception ex) {
            System.err.println("ERROR: " + ex);
        }
            }

           

    }
    }}
